﻿
using Humanizer.Configuration;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.Web.CodeGenerators.Mvc.Templates.BlazorIdentity;
using Mysqlx.Crud;
using Mysqlx.Prepare;
using Quartz;
using SageKing.OpenIddict.UI.Api;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static OpenIddict.Abstractions.OpenIddictConstants;

namespace SageKing.OpenIddict.UI.Api.Features;

public class OpenIddictUIApiFeature : FeatureBase
{
    public OpenIddictUIApiFeature(IModule module) : base(module)
    {
    }

    /// <summary>
    /// Represents the options for feature.
    /// </summary> 
    public Action<OpenIddictUIApiOptions> uiApiOptions { get; set; } = _ => { };

    /// <inheritdoc />
    public override void Apply(IConfigurationManager configurationManager, IHostEnvironment hostEnvironment)
    {
        ArgumentNullException.ThrowIfNull(configurationManager);
        Services.Configure(uiApiOptions);

        var options = new OpenIddictUIApiOptions();
        uiApiOptions?.Invoke(options);

        Services.AddRoutePrefix(options.RoutePrefix);

        Services.AddApiServices(uiApiOptions);

        //Services.AddAuthorizationServices(options.Policy);

    }
}
